package com.flying.vavr;

import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;

import java.util.Arrays;

public class BasicRulesApp {

    public static void main(String[] args) {
        KieServices services = KieServices.get();
        KieContainer container = services.getKieClasspathContainer();
        KieSession session = container.newKieSession("basicKS");
        Account account35 = new Account();
        account35.setBalance(35);
        session.insert(account35);

        Account account88 = new Account();
        account88.setBalance(88);
        session.insert(account88);

        Customer customer1 = new Customer();
        customer1.setName("account35");
        customer1.setAge(30);
        customer1.setAccounts(Arrays.asList(account35));
        session.insert(customer1);

        Customer customer2 = new Customer();
        customer2.setName("account88");
        customer2.setAge(20);
        customer2.setAccounts(Arrays.asList(account88));
        session.insert(customer2);

        int fired = session.fireAllRules();
        System.out.println("Fired times:" + fired);
        System.out.println("Customer1" + customer1);
        System.out.println("Customer2" + customer2);

        session.dispose();
    }
}
